<?php

/**
 * @author Thibaut Cromphaut, Gaïtano Boeraeve, Mathias Helin, Dimitry Dierickx
 * @copyright  Copyright (c) 2011 Artevelde University College Ghent 
 */

class Service_GatewayController extends Zend_Controller_Action
{

    public function init()
    {
        // Voor AMF hebben we layout noch view nodig, het is gewoon data zonder opmaak
        $this->_helper->layout()->disableLayout();       // Layout uitschakelen
        $this->_helper->viewRenderer->setNoRender(true); // View renderer uitschakelen

        // Autoloader voor Service- en VO-klasses
        // http://framework.zend.com/manual/en/learning.autoloading.resources.html
        $loader = new Zend_Loader_Autoloader_Resource(array(
            'basePath'  => dirname(__FILE__) . '/../',
            'namespace' => null,
        ));
        $loader->addResourceType('service', 'services'     ,'Service')
               ->addResourceType('vo'     , 'valueobjects' ,'VO'     )
        ;
    }

    public function indexAction()
    {
        return $this->_helper->redirector('amf');
    }

    public function amfAction()
    {
        $server = new Zend_Amf_Server();

        if (APPLICATION_ENV == 'development') {
            $server->setProduction(true); // Errorhandling. OPGELET! Voor productie op true zetten!
            
            /*// == ZamfBrowser ==
            $filename = APPLICATION_PATH . '/../browser/ZendAmfServiceBrowser.php';
            if (file_exists($filename)) {
                require_once $filename;
                $server->setClass('ZendAmfServiceBrowser');
                ZendAmfServiceBrowser::$ZEND_AMF_SERVER = $server;
            }
            // =================*/
        }

        /*
        //AUTHENTICATING & AUTHORIZATION        
        $auth = new Ahs_Amf_Auth();
        $server->setAuth($auth);

        $acl = new Ahs_Acl(true);
        $server->setAcl($acl);
        */
       
        $server->setClass('Service_GatewayService');
        $server->setClassMap($asClass = 'AnnouncementVO', $phpClass = 'VO_Announcement');
        $server->setClassMap($asClass = 'ArticleVO', $phpClass = 'VO_Article');
        $server->setClassMap($asClass = 'BookVO', $phpClass = 'VO_Book');
        $server->setClassMap($asClass = 'ChapterVO', $phpClass = 'VO_Chapter');
        $server->setClassMap($asClass = 'CommentVO', $phpClass = 'VO_Comment');
        $server->setClassMap($asClass = 'CourseVO', $phpClass = 'VO_Course');
        $server->setClassMap($asClass = 'MessageVO', $phpClass = 'VO_Message');
        $server->setClassMap($asClass = 'UserVO', $phpClass = 'VO_User');   
            
        error_reporting(0); // Foutmeldingen verstoren AMF, daarom zetten we ze uit.
        echo $server->handle();
    }

}

?>
